package com.doangeometrydash.main;

import java.io.IOException;

import org.andengine.engine.camera.BoundCamera;
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.WakeLockOptions;
import org.andengine.engine.options.resolutionpolicy.FillResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.ui.activity.SimpleBaseGameActivity;

import com.doangeometrydash.manager.ResourcesManager;
import com.doangeometrydash.manager.SceneManager;

import android.view.KeyEvent;

public class GameActivity extends SimpleBaseGameActivity
{
	private BoundCamera mCamera;
	private float CAMERA_WIDTH = 480;
	private float CAMERA_HEIGHT = 320;
	private EngineOptions mEngineOptions;
	private Scene currentScene;

	@Override
	public EngineOptions onCreateEngineOptions()
	{
		mCamera = new BoundCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
		this.mEngineOptions = new EngineOptions(false, ScreenOrientation.LANDSCAPE_SENSOR, new FillResolutionPolicy(), this.mCamera);
		mEngineOptions.getAudioOptions().setNeedsMusic(true).setNeedsSound(true);
		mEngineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
		mEngineOptions.getRenderOptions().setDithering(true);		

		return mEngineOptions;

	}

	@Override
	protected void onCreateResources() throws IOException
	{
		ResourcesManager.prepareManager(mEngine, this, mCamera, getVertexBufferObjectManager());		
	}

	@Override
	protected Scene onCreateScene()
	{		
		currentScene = SceneManager.getInstance().createSplashScene();
		mEngine.registerUpdateHandler(new TimerHandler(0.5f, new ITimerCallback()
		{
			public void onTimePassed(final TimerHandler pTimerHandler)
			{
				mEngine.unregisterUpdateHandler(pTimerHandler);
				currentScene = SceneManager.getInstance().createMenuScene();
			}
		}));
		return currentScene;
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event)
	{
		if (keyCode == KeyEvent.KEYCODE_BACK)
		{
			SceneManager.getInstance().getCurrentScene().onBackKeyPressed();
		}
		return false;
	}

}